import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-08-11
 * Time: 23:46
 */
public class Test77 {

    PriorityQueue<Integer> left;
    PriorityQueue<Integer> right;

    public Test77() {
        left = new PriorityQueue<>((a,b)->b-a);
        right = new PriorityQueue<>((a,b)->a-b);
    }

    public void addNum(int num) {
        if(left.size() == right.size()) {
            if(left.isEmpty() || num <= left.peek()) {
                left.offer(num);
            }else {
                right.offer(num);
                left.offer(right.poll());
            }
        } else {
            if(num <= left.peek()) {
                left.offer(num);
                right.offer(left.poll());
            } else {
                right.offer(num);
            }
        }
    }


    public double findMedian() {
        if(left.size() == right.size()) {
            return (left.peek() + right.peek()) * 2.0;
        } else {
            return left.peek();
        }
    }
}
